//
//  UserTableViewController.m
//  LWB_Project
//
//  Created by lanou3g on 15/11/11.
//  Copyright © 2015年 wangjianliang. All rights reserved.
//

#import "UserTableViewController.h"
#import "UserFirstTableViewCell.h"
#import "UserSecondTableViewCell.h"
#import "UserThreeTableViewCell.h"
#import "UserFourTableViewCell.h"
#import "UserFiveTableViewCell.h"
#import "UserSixTableViewCell.h"
#import "UserSevenTableViewCell.h"
#import "XHPathCover.h"
@interface UserTableViewController ()
{

}

@property (nonatomic, strong) UIView *headerView;

@property (nonatomic, strong) XHPathCover *pathCover;
@end

@implementation UserTableViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    //[self loadHeaderView];
    
    //self.title = @"PathCover";
    
    _pathCover = [[XHPathCover alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 250)];
    [_pathCover setBackgroundImage:[UIImage imageNamed:@"MenuBackground"]];
    [_pathCover setAvatarImage:[UIImage imageNamed:@"meicon.png"]];
    [_pathCover setInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Jack xhzengAIB", XHUserNameKey, @"1990-10-19", XHBirthdayKey, nil]];
    self.tableView.tableHeaderView = self.pathCover;
    
    __weak UserTableViewController *wself = self;
    [_pathCover setHandleRefreshEvent:^{
        [wself _refreshing];
    }];

}

- (void)_refreshing {
    // refresh your data sources
    
    __weak UserTableViewController *wself = self;
    double delayInSeconds = 2.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [wself.pathCover stopRefresh];
    });
}
//- (void)loadHeaderView
//{
//    UIImageView *headerImageView = [[UIImageView alloc] init];
//    headerImageView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height/3);
//    headerImageView.backgroundColor = [UIColor cyanColor];
//    headerImageView.image = [UIImage imageNamed:@"u=1745754702,3402027068&fm=21&gp=0.jpg"];
//    self.headerView =headerImageView;
//    self.tableView.tableHeaderView = headerImageView;
//}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark- scroll delegate

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    [_pathCover scrollViewDidScroll:scrollView];
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    [_pathCover scrollViewDidEndDecelerating:scrollView];
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
    [_pathCover scrollViewDidEndDragging:scrollView willDecelerate:decelerate];
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
    [_pathCover scrollViewWillBeginDragging:scrollView];
}



#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
 
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    
    return 7;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
       UITableViewCell *cell;

        switch (indexPath.row)
    {
               case 0:
                  cell = [tableView dequeueReusableCellWithIdentifier:@"userfirstcell" ];
                    if (cell == nil)
                    {
                        cell = [[[NSBundle mainBundle] loadNibNamed:@"UserFirstTableViewCell" owner:self options:nil] firstObject];
                    }
                   break;
               case 1:
                   cell = [tableView dequeueReusableCellWithIdentifier:@"usersecondcell" ];
                    if (cell == nil)
                    {
                        cell = [[[NSBundle mainBundle] loadNibNamed:@"UserSecondTableViewCell" owner:self options:nil] firstObject];
                    }
                   break;
                case 2:
                    cell = [tableView dequeueReusableCellWithIdentifier:@"userthreecell" ];
                    if (cell == nil)
                    {
                        cell = [[[NSBundle mainBundle] loadNibNamed:@"UserThreeTableViewCell" owner:self options:nil] firstObject];
                    }
                    break;


        case 3:
            cell = [tableView dequeueReusableCellWithIdentifier:@"userfourcell" ];
            if (cell == nil)
            {
                cell = [[[NSBundle mainBundle] loadNibNamed:@"UserFourTableViewCell" owner:self options:nil] firstObject];
            }

            
            break;
        case 4:
            cell = [tableView dequeueReusableCellWithIdentifier:@"userfivecell" ];
            if (cell == nil)
            {
                cell = [[[NSBundle mainBundle] loadNibNamed:@"UserFiveTableViewCell" owner:self options:nil] firstObject];
            }
            break;
        case 5:
            cell = [tableView dequeueReusableCellWithIdentifier:@"usersixcell" ];
            if (cell == nil)
            {
                cell = [[[NSBundle mainBundle] loadNibNamed:@"UserSixTableViewCell" owner:self options:nil] firstObject];
            }
            break;
        case 6:
            cell = [tableView dequeueReusableCellWithIdentifier:@"usersevencell" ];
            if (cell == nil)
            {
                cell = [[[NSBundle mainBundle] loadNibNamed:@"UserSevenTableViewCell" owner:self options:nil] firstObject];
                
            }

             break;

            default:
                    cell = [tableView dequeueReusableCellWithIdentifier:@"userfirstcell"];
                    if (cell == nil)
                    {
                        cell = [[[NSBundle mainBundle] loadNibNamed:@"UserFirstTableViewCell" owner:self options:nil] firstObject];
                    }
                   break;
     }
    
       return cell;
    
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
 {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath 
 {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath 
 {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Table view delegate

// In a xib-based application, navigation from a table can be handled in -tableView:didSelectRowAtIndexPath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
 {
    // Navigation logic may go here, for example:
    // Create the next view controller.
    <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:<#@"Nib name"#> bundle:nil];
    
    // Pass the selected object to the new view controller.
    
    // Push the view controller.
    [self.navigationController pushViewController:detailViewController animated:YES];
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
 {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
